home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 221 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.4 KB  |  58 lines

  1. Path: fido.asd.sgi.com!austern
  2. From: mkt@isun04.inf.uni-jena.de (Tilo Koerbs)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Explicit constructor call vs Temporaries
  5. Date: 01 Feb 1996 09:54:08 PST
  6. Organization: Lehrstuhl fuer Rechnerarchitektur- und kommunikation, FSU Jena
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4eq5p2$fpu@fsuj01.rz.uni-jena.de>
  9. References: <4e6plv$idn@eclipse.eng.sc.rolm.com>
  10. Reply-To: mkt@isun04.inf.uni-jena.de
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12. X-Original-Date: 1 Feb 1996 10:48:02 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMRD+cEy4NqrwXLNJAQESygIAo8MetEfyblp+r84Bvt1eaxl42v0Sortl
  15.     GvcHxkF3eLnDj9aEMhjb0fQ9CYQ0BEaRqG6iiWy4ZiIntGrvtmohFA==
  16.     =7Qw+
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19.  About the error message in this posted code:
  20.  
  21. > class T {
  22. >   T();
  23. >   ~T();
  24. > }
  25. > class X {
  26. >   X();
  27. >   ~X();
  28. >   f(T& t);
  29. > }
  30. > int main() {
  31. >   X x;
  32. >   x.f(T());  // Compiler complained on this line
  33. > }
  34.  
  35. The 'temporary' (it is an UNNAMED) T()-object is NOT const!
  36. Consider:
  37.     class T {
  38.     public:
  39.         T();
  40.         ~T();
  41.         void nonConstFct() {}
  42.     };
  43.  
  44.     int main() {
  45.         T().nonConstFct();  // Allowed!!!
  46.     }
  47.  
  48. And so the compiler should have no problem with this code!
  49. I compiled it without any problem!
  50.  
  51. Bye.
  52. ---
  53. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  54.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  55.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  56.